<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人中心</title>
<link rel="stylesheet" href="${ctx}/statics/css/bootstrap.min.css" />
<link rel="stylesheet" href="${ctx}/statics/css/font-awesome.min.css" />
<link rel="stylesheet"
	href="${ctx}/statics/js/layer/skin/default/layer.css" />
<link rel="stylesheet"
	href="${ctx}/statics/js/bootstrap-table/bootstrap-table.css" />
<link rel="stylesheet" href="${ctx}/statics/js/toastr/toastr.css" />
</head>
<body>
	<div id="main-content">
		<div class="row">
			<div class="col-md-12">
				<div class="panel panel-default">
					<div class="panel-heading">个人中心</div>
					<!-- /.panel-heading -->
					<div class="panel-body">
						<!-- 搜索                                                                -->
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<form class="form-horizontal" role="form" id="entity_form">
									<input type="text" name="id" hidden="true">
									<div class="form-group">
										<label class="control-label col-sm-3">姓名：</label>
										<div class="col-sm-8">
											<input type="text" class="form-control col-sm-3"
												name="userName">
										</div>
									</div>
									
									<div class="form-group">
										<label class="control-label col-sm-3">上传头像：</label>
										<div class="col-sm-8">
											<input type="file" id="touxiang" class="form-control col-sm-3"
												name="touxiang">
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-3">年龄：</label>
										<div class="col-sm-8">
											<input type="text" class="form-control col-sm-3"
												name="userAge">
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-3">学历：</label>
										<div class="col-sm-8">
											<select class="form-control" id="userDiploma"
												name="userDiploma">
												<option value="本科" selected="selected">本科</option>
												<option value="小学">小学</option>
												<option value="初中">初中</option>
												<option value="高中">高中</option>
												<option value="硕士">硕士</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-3">工资卡号：</label>
										<div class="col-sm-8">
											<input type="text" class="form-control col-sm-3"
												name="userBankcard">
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-3">身份证：</label>
										<div class="col-sm-8">
											<input type="text" class="form-control col-sm-3"
												name="userIdnum">
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-3">邮箱：</label>
										<div class="col-sm-8">
											<input type="text" class="form-control col-sm-3"
												name="userEmail">
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-3">地址：</label>
										<div class="col-sm-8">
											<input type="text" class="form-control col-sm-3"
												name="userAddress">
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-sm-3">手机：</label>
										<div class="col-sm-8">
											<input type="text" class="form-control col-sm-3"
												name="userMobile">
										</div>
									</div>
									<div class="form-group">
									<div align="center">
									<button class=" btn btn-sm btn-info" 
											 onclick="saveUser()">确定
										</button>
									</div>
									</div>
								</form>
							</div>
						</div>
					</div>
					<!-- panel body -->
				</div>
			</div>
		</div>
	</div>
	<%@ include file="../common.jsp"%>
	<script type="text/javascript"
		src="${ctx}/statics/js/jquery-form/jquery.form.js"></script>
</body>
<script type="text/javascript">
	$(function intData() {
		$.ajax({
			url : "${ctx}/user/getCurrentUser.do",
			type : "GET",
			data : {},
			success : function(row) {
				$("#entity_form")[0].reset();
				$("#entity_form input[name=id]").val(row.id);
				$("#entity_form input[name=userName]").val(row.userName);
				$("#entity_form input[name=userAge]").val(row.userAge);
				$("#entity_form input[name=userBankcard]").val(row.userBankcard);
				$("#entity_form input[name=userIdnum]").val(row.userIdnum);
				$("#entity_form input[name=userEmail]").val(row.userEmail);
				$("#entity_form input[name=userAddress]").val(row.userAddress);
				$("#entity_form input[name=userMobile]").val(row.userMobile);
				$("#userDiploma").val(row.userDiploma);
			}
		});
	});

	function saveUser() {
		$("#entity_form").attr("action", "${ctx}/user/saveUser.do");
		$("#entity_form").submit();

	}
	function checkForm() {
		var userPw = $("input[name=userPw]").val();
		if (userPw == '' || userPw == null) {
			alert("用户密码不能为空");
			return false;
		}
		var regForEmail = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
		var userEmail = $("input[name=userEmail]").val();
		if (!regForEmail.test(userEmail)) {
			//	toastr.warning("请填写正确的邮箱");
			alert("请填写正确的邮箱");
			return false;
		}
		var reg = /^[1][3,4,5,7,8][0-9]{9}$/;
		var userMobile = $("input[name=userMobile]").val();
		var flag = reg.test(userMobile);
		if (!flag) {
			//	toastr.warning("请填正确格式的联系号码");
			alert("请填正确格式的联系号码");
			return false;
		}

		return true;
	}
	
	//头像上传
	$("#entity_form input[type=file]").change(function(){
		var path=$(this).val();
		var imgname = path.substring(path.lastIndexOf("."), path.length);
		imgname = imgname.toLocaleLowerCase();
		if ((imgname != ".jpg") && (imgname != ".png") && (imgname != ".bmp")
				&& (imgname != ".jpeg")) {
			alert('只能上传jpg、png、bmp格式的图片');
			$(this).val("");
			return;
		}
		var maxSize = 400 * 1024;//400Kb
		 if (this.files[0].size > maxSize) {
			alert('图片大小不能超过400kb');
			$(this).val("");
			return;
		}
		var formData=new FormData();formData.append("touxiang",$("#touxiang")[0].files[0]);
		$.ajax({
			url : "${ctx}/user/uploadTouXiang.do",
			type :"post",
			contentType: false,  
     		processData: false, 
			data : formData,
			success : function(data){
				if (data.success) {
					alert("上传成功");
				} else {
					alert(data.errorMessage);
				}
			}
			
		});
	});
</script>
</html>